package com.zoe.vhr.rediscache;

import com.zoe.vhr.enums.RedisKeyEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.CountDownLatch;

/**
 * @Author Zoe.Zhang
 * @Date: 2021/08/06
 * @Description redis消息解析
 */
@Configuration
public class ReceiverRedisMessage {
    private static final Logger logger = LoggerFactory.getLogger(ReceiverRedisMessage.class);
    private CountDownLatch latch;
    @Autowired
    InitMenuWithRoleConfig initMenuWithRoleConfig;

    @Autowired
    public ReceiverRedisMessage(CountDownLatch latch) {
        this.latch = latch;
    }

    /**
     * 队列消息接收方法
     *
     * @param jsonMsg
     */
    public void receiveMessage(String jsonMsg) {
        logger.info("[开始消费REDIS消息队列数据...]");
        try {
            logger.info("开始消费队列数据====>{}", jsonMsg);
            initMenuWithRoleConfig.refreshMenu();
            logger.info("[消费REDIS消息队列数据成功.]");
        } catch (Exception e) {
            logger.error("[消费REDIS消息队列{}数据失败，失败信息:{}]", RedisKeyEnum.REFRESH_MENU_TOPIC.getKey(), e.getMessage());
        }
        latch.countDown();
    }

}
